export default {
    post: (url, data) => {
       return new Promise((res,rej)=>{
            let x = new XMLHttpRequest();
            x.open('POST', url)
            x.setRequestHeader('content-type', 'application/x-www-form-urlencoded')
            x.send(data)
            x.responseType = 'json';
            x.onreadystatechange = function () {
                if (x.readyState === 4) {
                    if (x.status >= 200 && x.status < 300) {
                        // console.log(JSON.parse(x.response));
                        // cb(x.response)
                        res(x.response)
                    }else{
                        rej(x.status)
                    }
                }
            }
       })
    },
    get: (url, data) => {
       return new Promise((res,rej)=>{
            let x = new XMLHttpRequest();
            x.open('get', url+'?'+data)
            x.send()
            x.responseType = 'json';
            x.onreadystatechange = function () {
                if (x.readyState === 4) {
                    if (x.status >= 200 && x.status < 300) {
                        // cb(x.response)
                        res(x.response)
                    }else{
                        rej(x.status)
                    }
                }
            }
       })
    },
}